package com.bazaaroid.mobile.android.adapter;

import java.util.ArrayList;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.bazaaroid.mobile.android.R;
import com.bazaaroid.mobile.rest.model.partner.*;

public class CategoryAdapter extends ArrayAdapter<CategoryItem> implements AdapterView.OnItemClickListener
{
    private ArrayList<CategoryItem> items;

    public CategoryAdapter(Context context, int textViewResourceId, ArrayList<CategoryItem> items) 
    {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    	View view = convertView;
    	if(view == null)
    	{
            LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.category_row, null);
            
    	}
    	CategoryItem category = items.get(position);
        if (category != null) 
        {
        	
        	
                TextView categoryText = (TextView)view.findViewById(R.id.category_text);
                if(categoryText != null)
                {
                	categoryText.setText(category.getName());
                }
        }
		return view;
	}
    
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
    {
    	Dialog dialog = new Dialog(getContext());
    	dialog.setTitle(String.format("%d/%d", position, items.size()));
    }
}
